/*
 * @Author: Laputa
 * @Version: V0.1
 * @Date: 2023-06-08 15:59:01
 * @LastEditors: Laputa
 * @LastEditTime: 2024-01-02 14:21:33
 * @Description: This file provides firmware functions that manage multiplex usage of the designated pin.
 *
 *
 * Copyright (c) 2023 by Levetop, All Rights Reserved.
 */

#include "lt168_pin.h"

/*******************************************************************************
 * Code
 ******************************************************************************/


/**
 * @brief PIN used as ADC_CH0
 * @return {void}
 */
void PIN_ADC_CH0_Default(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR &= ~(1 << 0);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as EPORT0_0
 * @return {void}
 */
void PIN_EPORT0_0(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR |= (1 << 0);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as ADC_CH1
 * @return {void}
 */
void PIN_ADC_CH1_Default(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR &= ~(1 << 1);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as EPORT0_1
 * @return {void}
 */
void PIN_EPORT0_1(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR |= (1 << 1);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as ADC_CH2
 * @return {void}
 */
void PIN_ADC_CH2_Default(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR &= ~(1 << 2);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as EPORT0_2
 * @return {void}
 */
void PIN_EPORT0_2(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR |= (1 << 2);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as ADC_CH3
 * @return {void}
 */
void PIN_ADC_CH3_Default(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR &= ~(1 << 3);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as EPORT0_3
 * @return {void}
 */
void PIN_EPORT0_3(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR |= (1 << 3);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as ADC_CH4
 * @return {void}
 */
void PIN_ADC_CH4_Default(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR &= ~(1 << 4);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as EPORT0_4
 * @return {void}
 */
void PIN_EPORT0_4(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR |= (1 << 4);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as ADC_CH5
 * @return {void}
 */
void PIN_ADC_CH5_Default(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR &= ~(1 << 5);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as EPORT0_5
 * @return {void}
 */
void PIN_EPORT0_5(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR |= (1 << 5);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as ADC_CH6
 * @return {void}
 */
void PIN_ADC_CH6_Default(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR &= ~(1 << 6);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as EPORT0_6
 * @return {void}
 */
void PIN_EPORT0_6(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR |= (1 << 6);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as ADC_CH7
 * @return {void}
 */
void PIN_ADC_CH7_Default(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR &= ~(1 << 7);
    OPTION->ADCCDISR &= 0x3FFF;
}
/**
 * @brief PIN used as EPORT0_7
 * @return {void}
 */
void PIN_EPORT0_7(void)
{
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x4000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0x8000);
    OPTION->ADCCDISR = ((OPTION->ADCCDISR & 0x3FFF) | 0xC000);
    OPTION->ADCCDISR |= (1 << 7);
    OPTION->ADCCDISR &= 0x3FFF;
}

/**
 * @brief PIN used as PWM
 * @return {void}
 */
void PIN_PWM_Default(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x1);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x2);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x3);
    OPTION->CCR &= ~(1 << 8);
    OPTION->CCR &= 0xFFFC;
}
/**
 * @brief PIN used as QSPI2
 * @return {void}
 */
void PIN_QSPI2(void)
{

    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR |= (1 << 8);
    OPTION->CCR &= 0xFFFC;
}

/**
 * @brief PIN used as RSTOUT
 * @return {void}
 */
void PIN_RSTOUT_Default(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR &= ~(1 << 11);
    OPTION->CCR &= 0xFFFC;
}
/**
 * @brief PIN used as EPORT1_6
 * @return {void}
 */
void PIN_EPORT1_6(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR |= (1 << 11);
    OPTION->CCR &= 0xFFFC;
}
/**
 * @brief PIN used as CLKOUT
 * @return {void}
 */
void PIN_CLKOUT_Default(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR &= ~(1 << 10);
    OPTION->CCR &= 0xFFFC;
}
/**
 * @brief PIN used as EPORT1_0
 * @return {void}
 */
void PIN_EPORT1_0(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR |= (1 << 10);
    OPTION->CCR &= 0xFFFC;
}

/**
 * @brief PIN used as TXD0
 * @return {void}
 */
void PIN_TXD0_Default(void)
{
    Bit_Clear(CCM->EPORT2FCR, 1 << 0);
}
/**
 * @brief PIN used as EPORT2_0
 * @return {void}
 */
void PIN_EPORT2_0(void)
{
    Bit_Set(CCM->EPORT2FCR, 1 << 0);
}
/**
 * @brief PIN used as RXD0
 * @return {void}
 */
void PIN_RXD0_Default(void)
{
    Bit_Clear(CCM->EPORT2FCR, 1 << 1);
}
/**
 * @brief PIN used as EPORT2_1
 * @return {void}
 */
void PIN_EPORT2_1(void)
{
    Bit_Set(CCM->EPORT2FCR, 1 << 1);
}

/**
 * @brief PIN used as TXD1
 * @return {void}
 */
void PIN_TXD1_Default(void)
{
    Bit_Clear(CCM->EPORT2FCR, 1 << 2);
}
/**
 * @brief PIN used as EPORT2_2
 * @return {void}
 */
void PIN_EPORT2_2(void)
{
    Bit_Set(CCM->EPORT2FCR, 1 << 2);
}

/**
 * @brief PIN used as RXD1
 * @return {void}
 */
void PIN_RXD1_Default(void)
{
    Bit_Clear(CCM->EPORT2FCR, 1 << 3);
}
/**
 * @brief PIN used as EPORT2_3
 * @return {void}
 */
void PIN_EPORT2_3(void)
{
    Bit_Set(CCM->EPORT2FCR, 1 << 3);
}

/**
 * @brief PIN used as TXD2
 * @return {void}
 */
void PIN_TXD2_Default(void)
{
    Bit_Clear(CCM->EPORT2FCR, 1 << 4);
}

/**
 * @brief PIN used as EPORT2_4
 * @return {void}
 * @note  this function has a higher priority than
 *        PIN_PGM and PIN_RXD2_TXD2.
 */
void PIN_EPORT2_4(void)
{
    Bit_Set(CCM->EPORT2FCR, 1 << 4);
}
/**
 * @brief PIN used as RXD2
 * @return {void}
 */
void PIN_RXD2_Default(void)
{
    Bit_Clear(CCM->EPORT2FCR, 1 << 5);
}
/**
 * @brief PIN used as EPORT2_5
 * @return {void}
 * @note  this function has a higher priority than
 *        PIN_PGM and PIN_RXD2_TXD2.
 */
void PIN_EPORT2_5(void)
{
    Bit_Set(CCM->EPORT2FCR, 1 << 5);
}
/**
 * @brief PIN used as CAN_TX
 * @return {void}
 */
void PIN_CANTX_Default(void)
{
    Bit_Clear(CCM->EPORT2FCR, 1 << 6);
}
/**
 * @brief PIN used as EPORT2_6
 * @return {void}
 */
void PIN_EPORT2_6(void)
{
    Bit_Set(CCM->EPORT2FCR, 1 << 6);
}
/**
 * @brief PIN used as CAN_RX
 * @return {void}
 */
void PIN_CANRX_Default(void)
{
    Bit_Clear(CCM->EPORT2FCR, 1 << 7);
}
/**
 * @brief PIN used as EPORT2_7
 * @return {void}
 */
void PIN_EPORT2_7(void)
{
    Bit_Set(CCM->EPORT2FCR, 1 << 7);
}
/**
 * @brief PIN used as EBI
 * @return {void}
 */
void PIN_EBI_Default(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR &= ~(1 << 15);
    OPTION->CCR &= 0xFFFC;
}
/**
 * @brief PIN used as RGB
 * @return {void}
 */
void PIN_RGB(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR |= (1 << 15);
    OPTION->CCR &= 0xFFFC;
}
/**
 * @brief PIN used as EPORT1_1245
 * @return {void}
 */
void PIN_EPORT1_1245(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR &= ~(1 << 15);
    OPTION->CCR &= 0xFFFC;

    /* EBI switch EPORT1_1,EPORT1_2,EPORT1_4,EPORT1_5 */
    EBI->IOCR |= 1 << 1;

    Bit_Set(EBI->IOCR, 1 << 17);
}
/**
 * @brief PIN used as EBI_Control_Signal
 * @return {void}
 */
void PIN_EBI_Control_Signal_Default(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR &= ~(1 << 15);
    OPTION->CCR &= 0xFFFC;
    EBI->IOCR &= ~(1 << 1);
}

/**
 * @brief PIN used as Programme
 * @return {void}
 */
void PIN_PGM_Default(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR &= ~(1 << 12);
    OPTION->CCR &= 0xFFFC;
}
/**
 * @brief PIN used as SCI2
 * @return {void}
 */
void PIN_RXD2_TXD2(void)
{
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x01);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x02);
    OPTION->CCR = ((OPTION->CCR & 0xFFFC) | 0x03);
    OPTION->CCR |= (1 << 12);
    OPTION->CCR &= 0xFFFC;
}
/*!<---------------End of Code--------------->!*/
